<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>后台-用户订单中心</title>
    <spring:url value="/resources/jquery-easyui-1.5.3/themes/default/easyui.css"
                var="easyuiCss"/>
    <link href="${easyuiCss}" rel="stylesheet"/>

    <spring:url value="/resources/jquery-easyui-1.5.3/themes/icon.css"
                var="easyuiIcon"/>
    <link href="${easyuiIcon}" rel="stylesheet"/>

    <script src="<c:url value="/resources/jquery-easyui-1.5.3/jquery.min.js" />"></script>

    <script src="<c:url value="/resources/jquery-easyui-1.5.3/jquery.easyui.min.js" />"></script>

    <script src="<c:url value="/resources/jquery-easyui-1.5.3/locale/easyui-lang-zh_CN.js" />"></script>


</head>
<body style="margin:1px;">
<table id="dg" title="订单管理" class="easyui-datagrid"
         data-options="
            fit:true,
            rownumbers:true,
            autoRowHeight:true,
            pagination:true,
            SingleSelect:false,
            pageSize:10,
            pageList: [10, 20, 30],
            url:'<%=request.getContextPath()%>/manager/adminTicketOrderList',
            method:'get',
            toolbar:'#tb'">
    <thead>
    <tr>
        <th field="cb" checkbox="true" align="center"></th>
        <th field="id" width="50" align="center">编号</th>
        <th field="orderno" width="200" align="center">订单号</th>
        <th field="ordertime" width="175" align="center">订购时间</th>
        <th field="flightName" width="150" align="center" >航班名称</th>
        <th field="userName" width="100" align="center" >用户名</th>
        <th field="spacetype" width="100" align="center">座舱类型</th>
        <th field="price" width="100" align="center">票价</th>
        <th field="num" width="100" align="center">订购数量</th>
        <th field="totalprice" width="100" align="center">总价</th>
    </tr>
    </thead>
</table>
<div id="tb">
    <div>
        <a href="javascript:openTicketOrderAddDialog()" class="easyui-linkbutton" iconCls="icon-add" plain="true">添加</a>
        <a href="javascript:openTicketOrderModifyDialog()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
        <a href="javascript:deleteTicketOrder()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除订单</a>
    </div>
    <div>
        &nbsp;订单号：<input type="text" id="s_ticketOrderNo" size="20"
                         onkeydown="if(event.keyCode==13) searchTicketOrder()"/>
        &nbsp;用户名：<input type="text" id="s_ticketOrderUserName" size="20"
                         onkeydown="if(event.keyCode==13) searchTicketOrder()"/>
        &nbsp;航班名：<input type="text" id="s_ticketOrderFlightName" size="20"
                         onkeydown="if(event.keyCode==13) searchTicketOrder()"/>
        <a href="javascript:searchTicketOrder()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
    </div>
</div>
<div id="dlg" class="easyui-dialog" style="width: 700px;height:350px;padding: 10px 20px"
     closed="true" buttons="#dlg-buttons">
    <form id="fm" method="post">
        <table cellspacing="8px">

            <tr>
                <td>航班名称：</td>
                <td>
                    <input class="easyui-combobox" id="aircraft" name="flightid" data-options="
                    panelHeight:'auto',editable:false,valueField:'id',textField:'name',url:'/MavenDemo/flight/comboList'"/>
                </td>
                <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                <td>订购时间：</td>

                <td>
                    <input class="easyui-datetimebox" name="time" data-options="required:true"  style="width:150px">

            </tr>

            <tr>
                <td>用户名：</td>
                <td>
                    <input id="name" class="easyui-combobox" name="userid"
                           data-options="valueField:'id',textField:'username',url:'/MavenDemo/user/comboList'">
                </td>
                <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                <td>航班类型：</td>
                <td>
                    <select class="easyui-combobox" id="flighttype" name="spacetype" style="width: 154px;" editable="false" panelHeight="auto">
                        <option value="">请选择座舱类型</option>
                        <option value="头等舱">头等舱</option>
                        <option value="经济舱">经济舱</option>
                    </select>
                </td>
            </tr>

            <tr>
                <td>订购数量：</td>
                <td><input type="text" id="ecTicketTotal" name="num" class="easyui-validatebox" required="true"/></td>
                <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                <td>价格：</td>
                <td><input type="text" id="price" name="price" class="easyui-validatebox" required="true"/></td>
                <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                <%--<td>总价：</td>--%>
                <td><input type="text" value="123"  id="totalprice" name="totalprice" class="easyui-validatebox" required="true" hidden/></td>
            </tr>

        </table>
    </form>
</div>

<div id="dlg-buttons">
    <a href="javascript:saveFlight()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
    <a href="javascript:closeFlightDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
</div>
</body>
<script type="text/javascript">
    function searchTicketOrder() {
        console.log($("#s_ticketOrderFlightName").val())
        $("#dg").datagrid('load', {
            "orderno": $("#s_ticketOrderNo").val(),
            "flightName": $("#s_ticketOrderFlightName").val(),
            "userName": $("#s_ticketOrderUserName").val(),

        });

    }
    function deleteTicketOrder() {
        var selectedRows = $("#dg").datagrid('getSelections');
        if (selectedRows.length == 0) {
            $.messager.alert("系统提示", "请选择要删除的数据！");
            return;
        }
        var strIds = [];
        for (var i = 0; i < selectedRows.length; i++) {
            strIds.push(selectedRows[i].id);
        }
        var ids = strIds.join(",");
        $.messager.confirm("系统提示", "您确认要删除这<font color=red>" + selectedRows.length + "</font>条数据吗？", function (r) {
            if (r) {
                $.post("/MavenDemo/manager/adminDeleteTicketOrder", {ids: ids}, function (result) {
                    if (result.success) {
                        $.messager.alert("系统提示", "数据已成功删除！");
                        $("#dg").datagrid("reload");
                    } else {
                        $.messager.alert("系统提示", "删除失败！");
                    }
                }, "json");
            }
        });

    }


    function openTicketOrderAddDialog(){
        $("#dlg").dialog("open").dialog("setTitle","添加订单");
        url="/MavenDemo/ticketOrder/saveTicketOrder";
    }

    function saveFlight(){
        $("#fm").form("submit",{
            url:url,
            onSubmit:function(){
                // if($("#flightType").combobox("getValue")==""){
                //     $.messager.alert("系统提示","请选择航班类型");
                //     return false;
                // }
                // if($("#aircraft").combobox("getValue")==""){
                //     $.messager.alert("系统提示","请选择使用客机");
                //     return false;
                // }
                $("#totalprice").val($("#price").val()*$("#ecTicketTotal").val())
            },
            success:function(result){
                console.log("success")
                var result=eval('('+result+')');
                if(result.success){
                    $.messager.alert("系统提示","保存成功");
                    resetValue();
                    $("#dlg").dialog("close");
                    $("#dg").datagrid("reload");
                }else{
                    $.messager.alert("系统提示","保存失败");
                    return;
                }
            }
        });
    }

    function openTicketOrderModifyDialog(){
        var selectedRows=$("#dg").datagrid('getSelections');
        if(selectedRows.length!=1){
            $.messager.alert("系统提示","请选择一条要编辑的数据！");
            return;
        }
        var row=selectedRows[0];
        console.log(row);
        alert(row.ectickettotal+"   "+row.fctickettotal)
        $("#dlg").dialog("open").dialog("setTitle","编辑航班信息");
        $("#name").val(row.name);
        $("#flightType").combobox("setValue",row.flighttype);
        $("#fromCity").val(row.fromcity);
        $("#fromTime").datebox("setValue",row.fromtime);
        $("#toCity").val(row.tocity);
        $("#ecTicketTotal").val(row.ectickettotal);
        $("#fcPrice").val(row.fcprice);
        $("#fcTicketTotal").val(row.fctickettotal);
        $("#aircraft").combobox("setValue",row.aircraftid);
        $("#toTime").datebox("setValue",row.totime);
        $("#ecPrice").val(row.ecprice);
        url="/MavenDemo/flight/save?id="+row.id;
    }

    function resetValue(){
        $("#name").val("");
        $("#flightType").combobox("setValue","");
        $("#fromCity").val("");
        $("#fromTime").datebox("setValue","");
        $("#toCity").val("");
        $("#toTime").datebox("setValue","");
        $("#ecPrice").val("");
        $("#ecTicketTotal").val("");
        $("#fcPrice").val("");
        $("#fcTicketTotal").val("");
        $("#aircraft").combobox("setValue","");
    }

    function closeFlightDialog(){
        $("#dlg").dialog("close");
        resetValue();
    }

    function checkForm(){
        <%--var num=$("#num").val();--%>
        <%--if(num==null||num==""){--%>
        <%--alert("请输入订购数量！");--%>
        <%--return false;--%>
        <%--}--%>
        <%--if($('input[name="price_type"]:checked').val().split("-")[1]==1){  // 经济舱--%>
        <%--if(num>${flight.ecTicketRemain}||5){--%>
        <%--alert("经济舱余票为${flight.ecTicketRemain}，请调整订购数量！");--%>
        <%--return false;--%>
        <%--}--%>
        <%--}else{--%>
        <%--if(num>${flight.fcTicketRemain}){--%>
        <%--alert("头等舱余票为${flight.fcTicketRemain}，请调整订购数量！");--%>
        <%--return false;--%>
        <%--}--%>
        <%--}--%>
        return true;
    }

    function formatFlightName(val, row) {
        return row.flight.name;
    }

    function formatUserName(val, row) {
        return row.user.userName;
    }
</script>

</html>